home *** CD-ROM | disk | FTP | other *** search
- unit Usniff;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ExtCtrls, Clipbrd;
-
- type
- TForm1 = class(TForm)
- OpenDialog: TOpenDialog;
- Button1: TButton;
- CurrentFile: TLabel;
- Bevel1: TBevel;
- FileList: TListBox;
- Label1: TLabel;
- Button2: TButton;
- Label2: TLabel;
- Label3: TLabel;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses DLLPeek;
-
- function FormatPathToFit (const fName: String; Canvas: TCanvas; AvailWidth: Integer): String;
- var
- Idx: Integer;
- Drive: String[4];
- Path, Name, Ext: String;
-
- procedure ShortenPath;
- var
- StartSlash: Boolean;
- begin
- if Path = '\' then Path := '' else begin
- if Path[1] = '\' then begin
- StartSlash := True;
- Path := Copy (Path, 2, 255);
- end
- else StartSlash := False;
-
- if Path[1] = '.' then Path := Copy (Path, 5, 255);
-
- Idx := Pos ('\', Path);
- if Idx <> 0 then Path := '...\' + Copy (Path, Idx + 1, 255)
- else Path := '';
-
- if StartSlash then Path := '\' + Path;
- end;
- end;
-
- begin
- Result := fName;
- Path := ExtractFilePath (Result);
- Name := ExtractFileName (Result);
- Idx := Pos ('.', Name);
- if Idx > 0 then Name[0] := Chr (Idx - 1);
- Ext := ExtractFileExt (Result);
- if Path [2] = ':' then begin
- Drive := Copy (Path, 1, 2);
- Path := Copy (Path, 3, 255);
- end
- else Drive := '';
-
- while ((Path <> '') or (Drive <> '')) and (Canvas.TextWidth (Result) > AvailWidth) do
- begin
- if Path = '\...\' then begin
- Drive := '';
- Path := '...\';
- end
- else if Path = '' then Drive := ''
- else ShortenPath;
-
- Result := Drive + Path + Name + Ext;
- end;
- end;
-
- procedure TForm1.Button1Click (Sender: TObject);
- var
- TheList: TStringList;
- begin
- if OpenDialog.Execute then begin
- CurrentFile.Caption := FormatPathToFit (OpenDialog.FileName, Canvas, CurrentFile.Width);
- TheList := TStringList.Create;
- TheList.Sorted := True;
- GetDLLList (OpenDialog.FileName, TheList);
- FileList.Items.Assign (TheList);
- TheList.Free;
- end;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- RenderBuffer: PChar;
- Idx, ByteCount: Integer;
- Buff: array [0..255] of Char;
- begin
- ByteCount := 0;
- for Idx := 0 to FileList.Items.Count - 1 do
- Inc (ByteCount, Length (FileList.Items [Idx]) + 2);
- Inc (ByteCount);
-
- { Allocate a buffer for rendering the DLL list }
- GetMem (RenderBuffer, ByteCount);
- try
- RenderBuffer [0] := #0;
- for Idx := 0 to FileList.Items.Count - 1 do
- lstrcat (RenderBuffer, StrPCopy (Buff, FileList.Items [Idx] + #13 + #10));
- Clipboard.SetTextBuf (RenderBuffer);
- MessageDlg ('DLL list has been copied to the Windows clipboard.',
- mtInformation, [mbOK], 0);
- finally
- FreeMem (RenderBuffer, ByteCount);
- end;
- end;
-
- end.
-
-
-
-